to remove/FunctionsTOcleandata.R

# What to exclude from the analysis, delete rows that
#  NA's in logOR/RR (no need)
# 1. NA's in response (r)
# 2. NA's in sample size (n)
# 3. studies report with same dose in all arms
# 4. NA's in dose
# 5. single arm studies

#*** Exclude flexible dose (ASK Georgia)
removeNAdosresdata.fun=function(dataset,nametoexclude="toexclude") # ,studyid,logRR,r,n,dose
{
  # this function takes a database and exclude studies that will cause problems in fiting the dosres model for a particular outcome
  # It return the same database but in the end it has a variable that tells you which studies to exclude
  # Give a name to that column in the nametoexclude variable
  originaldimension=dim(dataset)[2]
  r=eval(substitute(r), dataset)
  dose=eval(substitute(dose), dataset)
  n=eval(substitute(n), dataset)
  studyid=eval(substitute(studyid), dataset)

  #exlude missing logOR: NO need as OR will be NA if r or n is NA
  # out0=unique(studyid[is.na(logOR)])

  # 1. exclude studies with NA events
  out1=unique(studyid[is.na(r)|r ==0])

  # 2. exclude studies with  NA sample size
  out2=unique(studyid[is.na(n)])

  # 3. exclude those studies with the same dose in all arms
  out3=unique(studyid)[tapply(dose,studyid,max)==tapply(dose,studyid,min)]

  # 4. exclude those studies with NA dose
  out4=unique(studyid[is.na(dose)])

  # 5. exclude studies that report the same dose

  # add column with include/exclude studies T/F
  dataset$exclude <- ifelse(studyid%in%c(out1,out2,out3,out4),TRUE,FALSE)
  # toexclude=as.data.frame(studyid%in%c(out0,out1,out2,out3))
  # names(toexclude)=c(nametoexclude)
  return(list(dataset=dataset,out=c(out1,out2,out3,out4)))
}


exludesinglearmsdata.fun<-function(dataset,studyid)
{
  studyid=eval(substitute(studyid), dataset)
  singlearmstudies=names(table(studyid))[table(studyid)<2]
  dataset2=dataset[is.na(match(studyid,singlearmstudies)),]
  dataset2
  #returns a dataset with the same columns after excluding single arms
}
htx-r/doseresNMA documentation built on Jan. 28, 2021, 5:32 a.m.